package com.jgraves.WikiToSpeech;


import java.util.ArrayList;
import java.util.regex.Matcher;

import com.jgraves.WikiToSpeech.objects.Rule;

/** Responds to commandString based on combination of rules from configuration and script
 * @author johngraves
 *
 */
public class RespondToCommand {

	public static Rule respond(String commandString, ArrayList<Rule> rules) {
		Rule mMatchingRule = new Rule();
		for (Rule rule:rules) {
			if (null!=rule) {
				// Note that ASK rules do not have rulePatterns
				if (null!=commandString && null!=rule.getRulePattern()) {
					Matcher m = rule.getRulePattern().matcher(commandString);
					if (m.find()) { 
						mMatchingRule = rule;
						break;
					}
				}
			}
		}
		print("Returning matching rule named:" + mMatchingRule.getRuleName());
		return mMatchingRule;
	}
	// -----------------------
	public static void print(Object obj){
		System.out.println(obj.toString());
	}
}
